﻿using NUnit.Framework;
using Validate.Extensions;

namespace Validate.UnitTests
{
    [TestFixture]
    public class ValidatorTests_IsTrueIsFalse
    {
        [Test]
        public void ShouldPassForIsTrueAndFailForIsFalse()
        {
            var person = new Person {Goals = 101, Fouls = 9};
            
            var validator = person.Validate().IsTrue(v => v.Goals > 100 && v.Fouls < 10, "Goals should be greater than 100 and fouls should be less than 10.");
            Assert.IsTrue(validator.IsValid);

            validator = person.Validate().IsFalse(v => v.Goals > 100 && v.Fouls < 10, "Goals should be greater than 100 and fouls should be less than 10.");
            Assert.IsFalse(validator.IsValid);
        }

        [Test]
        public void ShouldFailForIsTrueAndPassForIsFalse()
        {
            var person = new Person { Goals = 99, Fouls = 11 };

            var validator = person.Validate().IsTrue(v => v.Goals > 100 && v.Fouls < 10, "Goals should be greater than 100 and fouls should be less than 10.");
            Assert.IsFalse(validator.IsValid);

            validator = person.Validate().IsFalse(v => v.Goals > 100 && v.Fouls < 10, "Goals should be greater than 100 and fouls should be less than 10.");
            Assert.IsTrue(validator.IsValid);
        }

        [Test]
        public void ShouldBeAbleToVerifyAutoGeneratedValidationMessage1()
        {
            var person = new Person { IsTrue = false};
            var validator = person.Validate(new ValidationOptions { StopOnFirstError = false })
                .IsTrue(p => p.IsTrue);
            Assert.That(validator.Errors[0].Message, Is.EqualTo("Person.IsTrue should be true."));

            person = new Person { IsTrue = true };
            validator = person.Validate(new ValidationOptions { StopOnFirstError = false })
                        .IsFalse(p => p.IsTrue);
            Assert.That(validator.Errors[0].Message, Is.EqualTo("Person.IsTrue should be false."));
        }
    }
}